import * as $http from '@/utlis/interface/Wode'
import { reactive, ref } from 'vue'
import { forDate } from '@/utlis/time'
export default (proxy: any) => {
  const riderCapitalList = reactive<any[]>([])
  const baseData = reactive<any>({
    balance: uni.getStorageSync('balance'),
    pageNo: 1,
    pageSize: 10,
    toLower_show: true,
  })
  const accountBalance = (Type: any) => {
    let data = {
      pageNo: baseData.pageNo,
      pageSize: baseData.pageSize,
    }
    if (Type == 1 && baseData.toLower_show) {
      $http
        .yesterdayIncome(data, proxy)
        .then((res: any) => {
          res.data?.forEach((item: any, index: any) => {
            item.createTime = forDate(item.createTime)
            item.updateTime = forDate(item.updateTime)
            riderCapitalList.push(item)
          })
        })
        .catch((err: any) => {
          if (err.code == -1) baseData.toLower_show = false
        })
    } else {
      $http
        .accountDetails(data, proxy)
        .then((res: any) => {
          res.data?.forEach((item: any, index: any) => {
            item.orderTime = forDate(item.orderTime)
            riderCapitalList.push(item)
          })
        })
        .catch((err: any) => {
          if (err.code == -1) baseData.toLower_show = false
        })
    }
  }
  // 列表触底加载数据
  const scrollTop = ref(0)
  const toLower = (e: any) => {
    if (baseData.toLower_show) {
      baseData.pageNo++
      accountBalance(proxy.$page.options.Type)
    }
  }
  return {
    accountBalance,
    riderCapitalList,
    baseData,
    toLower,
    scrollTop,
  }
}
